//
//  NSObject+LG.m
//  ALS3.0
//
//  Created by guomianxiang on 2017/5/3.
//  Copyright © 2017年 guomianxiang. All rights reserved.
//

#import "NSObject+LG.h"
#import <objc/runtime.h>

@implementation NSObject (LG)

- (NSMutableArray<NSString *> *)getPropertiesWith:(id)value {
    
    NSMutableArray *array = [NSMutableArray array];
    NSString *className = NSStringFromClass([value class]);
    const char *cClassName = [className UTF8String];
    
    id classM = objc_getClass(cClassName);
    unsigned int outCount, i;
    objc_property_t *properties = class_copyPropertyList(classM, &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        NSString *attributeName = [NSString stringWithUTF8String:property_getName(property)];
        
        [array addObject:attributeName];
    }
    return array;
    /*
     NSLog(@"----++++++++----");
     
     NSMutableArray *memberArr = [NSMutableArray array];
     
     unsigned int count = 0;
     Ivar *menbers = class_copyIvarList([value class], &count);
     NSLog(@"%@",[value class]);
     
     for (int i = 0; i < count; i++) {
     Ivar var = menbers[i];
     const char *memberName = ivar_getName(var);
     NSString *memberStr = [NSString stringWithCString:memberName encoding:NSUTF8StringEncoding];
     NSLog(@"--%@",memberStr);
     [memberArr addObject:memberStr];
     }
     return memberArr;
     */
}

- (NSMutableArray<NSString *> *)getProperties {
    
    id value = self;
    NSMutableArray *array = [NSMutableArray array];
    NSString *className = NSStringFromClass([value class]);
    const char *cClassName = [className UTF8String];
    
    id classM = objc_getClass(cClassName);
    unsigned int outCount, i;
    objc_property_t *properties = class_copyPropertyList(classM, &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        NSString *attributeName = [NSString stringWithUTF8String:property_getName(property)];
        
        [array addObject:attributeName];
    }
    return array;
    /*
     NSLog(@"----++++++++----");
     
     NSMutableArray *memberArr = [NSMutableArray array];
     
     unsigned int count = 0;
     Ivar *menbers = class_copyIvarList([value class], &count);
     NSLog(@"%@",[value class]);
     
     for (int i = 0; i < count; i++) {
     Ivar var = menbers[i];
     const char *memberName = ivar_getName(var);
     NSString *memberStr = [NSString stringWithCString:memberName encoding:NSUTF8StringEncoding];
     NSLog(@"--%@",memberStr);
     [memberArr addObject:memberStr];
     }
     return memberArr;
     */
}




@end
